#include <algorithm>
#include <iostream>
#include <stack>

bool isValid(int a[], int n) {
    std::stack<int> stack_s;
    int x = 1;
    for (int i = 0; i < n; i++) {
        if (stack_s.empty() || stack_s.top() < a[i]) {
            while (x <= a[i])
                stack_s.push(x++);
        }
        if (stack_s.empty() || stack_s.top() != a[i])
            return false;
        stack_s.pop();
    }
    return true;
}
int main() {
    int n, a[25], cnt = 20;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        a[i] = i + 1;
    }
    do {
        if (isValid(a, n)) {
            for (int i = 0; i < n; i++) {
                std::cout << a[i];
            }
            std::cout << std::endl;
            cnt -= 1;
        }
    } while (std::next_permutation(a, a + n) && cnt);
    return 0;
}